package com.xuetang9.fujian.net.request;

import com.xuetang9.fujian.net.server.ECQServer;
import com.xuetang9.fujian.net.server.SocketHandler;

import java.util.HashMap;
import java.util.concurrent.TimeUnit;

/**
 * @describe: client disconnect
 * @author:fujian
 * @date:2021/6/13
 * @Version: V1.0
 * @Package: com.xuetang9.fujian.net.request
 */
@SuppressWarnings("all")
public class ClientExitRequestHandler extends AbstractRequestHandler{
    @Override
    public void handleRequest(HashMap<String, Object> message, SocketHandler handler, ECQServer server) {
        boolean isExit = (boolean) message.get("exit");
        if (isExit){
            HashMap<String, Object> responseMessage = new HashMap<>();
            responseMessage.put("success",true);
            responseMessage.put("handlerClass","com.xuetang9.fujian.net.reponse.ExitResponseHandler");
            handler.sendMessage(responseMessage);
            try {
                TimeUnit.MILLISECONDS.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            handler.setStatus(SocketHandler.CLOSE);
            handler.close();
            System.out.println("exit success");
        }
    }
}
